package cn.doctor.assistant.pad.ui.zhuanzhen;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.doctor.assistant.pad.R;
import cn.doctor.assistant.pad.entity.TransferBean;

/**
 * Created by jiaolf on 2016/4/15.
 */
public class TransferAdapter extends BaseAdapter {
    private List<TransferBean> items;
    private Context context;

    public TransferAdapter(Context context, List<TransferBean> data) {
        this.context = context;
        items = data;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_transfer_info, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        TransferBean transferBean = items.get(position);
        holder.listItemId.setText((position+1)+"");
        holder.listItemName.setText(transferBean.getRealName());
        holder.listItemSex.setText(transferBean.getSex());
        holder.listItemPhone.setText(transferBean.getPhone());
        holder.listItemFromOrg.setText(transferBean.getOrgName());
        holder.listItemFromDoctor.setText(transferBean.getDoctor());
        holder.listItemDiagnose.setText(transferBean.getNote());
        holder.listItemDate.setText(transferBean.getCreateDate());

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.list_item_id)
        TextView listItemId;
        @InjectView(R.id.list_item_name)
        TextView listItemName;
        @InjectView(R.id.list_item_sex)
        TextView listItemSex;
        @InjectView(R.id.list_item_phone)
        TextView listItemPhone;
        @InjectView(R.id.list_item_from_org)
        TextView listItemFromOrg;
        @InjectView(R.id.list_item_from_doctor)
        TextView listItemFromDoctor;
        @InjectView(R.id.list_item_diagnose)
        TextView listItemDiagnose;
        @InjectView(R.id.list_item_date)
        TextView listItemDate;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
